import { queryOptions } from '@/api/dict'

// 获取字典列表
export const getDictOptions = async (dictCode) => {
  let arr = null
  const res = await queryOptions(dictCode)
  arr = res.data
  return arr
}

// 获取字典的值
export const getDictLabel = (value, dict) => {
  let dictList = []
  if (typeof dict === 'string') {
    dictList = getDictOptions(dict)
  } else if (
    typeof dict === 'object' &&
    Array.isArray(dict)
  ) {
    dictList = dict
  }

  let label = value
  dictList.forEach((item) => {
    if (item.dictValue.toString() === value.toString()) {
      label = item.dictText
    }
  })

  return label
}
